package com.btex.app;

import android.content.Intent;
import android.graphics.Color;
import android.icu.text.SimpleDateFormat;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.btex.app.entity.OTCOrderDetailInfo;
import com.btex.app.tools.MicroAVLIDialog;
import com.btex.app.tools.OTCBigImagDialog;
import com.btex.app.tools.OTCCancelConfirmDialog;
import com.btex.app.tools.OTCConfirmDialog;
import com.btex.app.tools.Util;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.iwgang.countdownview.CountdownView;

public class OTCOrderdetailActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_menu)
    TextView mTvMenu;
    @BindView(R.id.rl_title)
    RelativeLayout mRlTitle;
    @BindView(R.id.otc_activity_tv_derdettail_time)
    TextView mOtcActivityTvDerdettailTime;
    @BindView(R.id.otc_activity_tv_derdettail_danhao)
    TextView mOtcActivityTvDerdettailDanhao;
    @BindView(R.id.otc_activity_tv_derdettail_number)
    TextView mOtcActivityTvDerdettailNumber;
    @BindView(R.id.otc_activity_tv_derdettail_price)
    TextView mOtcActivityTvDerdettailPrice;
    @BindView(R.id.otc_activity_tv_derdettail_money)
    TextView mOtcActivityTvDerdettailMoney;
    @BindView(R.id.otc_activity_tv_derdettail_shoukuan)
    TextView mOtcActivityTvDerdettailShoukuan;
    @BindView(R.id.otc_activity_tv_derdettail_zhanghaho)
    TextView mOtcActivityTvDerdettailZhanghaho;
    @BindView(R.id.otc)
    LinearLayout mOtc;
    @BindView(R.id.otc_activity_tv_derdettail_countdown)
    CountdownView mOtcActivityTvDerdettailCountdown;
    @BindView(R.id.otc_activity_tv_derdettail_pay)
    TextView mOtcActivityTvDerdettailPay;
    @BindView(R.id.otc_activity_tv_derdettail_imag)
    ImageView mOtcActivityTvDerdettailImag;
    @BindView(R.id.otc_activity_tv_derdettail_call)
    TextView mOtcActivityTvDerdettailCall;
    @BindView(R.id.otc_activity_tv_derdettail_shenshu)
    TextView mOtcActivityTvDerdettailShenshu;
    @BindView(R.id.otc_activity_tv_derdettail_diss)
    TextView mOtcActivityTvDerdettailDiss;
    @BindView(R.id.otc_activity_tv_derdettail_yi)
    TextView mOtcActivityTvDerdettailYi;
    @BindView(R.id.otc_activity_tv_derdettail_pay_type)
    TextView mOtcActivityTvDerdettailPayType;
    @BindView(R.id.otc_activity_tv_derdettail_maima)
    TextView mOtcActivityTvDerdettailMaima;
    @BindView(R.id.otc_activity_tv_derdettail_opposite_name)
    TextView mOtcActivityTvDerdettailOppositeName;
    @BindView(R.id.otc_activity_lin_derdettail_opposite_name)
    LinearLayout mOtcActivityLinDerdettailOppositeName;
    @BindView(R.id.otc_activity_tv_derdettail_swip)
    SwipeRefreshLayout mOtcActivityTvDerdettailSwip;
    @BindView(R.id.otc_activity_tv_derdettail_order)
    TextView mOtcActivityTvDerdettailOrder;
    @BindView(R.id.tv_otc_la)
    ImageView mTvOtcLa;
    @BindView(R.id.otc_activity_tv_derdettail_zhanghaho_type)
    TextView mOtcActivityTvDerdettailZhanghahoType;

    //银行
    @BindView(R.id.otc_activity_tv_derdettail_zhanghaho_type_name)
    TextView otc_activity_tv_derdettail_zhanghaho_type_name;

    //银行卡号
    @BindView(R.id.otc_activity_tv_derdettail_zhanghaho_name)
    TextView otc_activity_tv_derdettail_zhanghaho_name;


    private String mOther_contact;
    private String mImg;
    private String mTrade_status;
    private String mData;
    private MicroAVLIDialog mMicroAVLIDialog;
    private OTCOrderDetailInfo mOtcOrderDetailInfo;
    private long mEnd;
    private Long mDate;
    public boolean isShow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
//        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_otcorderdetail);
        ButterKnife.bind(this);
        EventBus.getDefault().register(this);
        mTvTitle.setText("交易详情");

        initListener();
        mMicroAVLIDialog = new MicroAVLIDialog(this);
        mData = getIntent().getStringExtra("data");
        mMicroAVLIDialog.show();
        initDatas();


    }

    private void initListener() {
        mOtcActivityTvDerdettailSwip.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {

                initDatas();
            }
        });
    }

    private void initDatas() {

        int num = (int) ((Math.random() * 9 + 1) * 100000);

        OkGo.<String>get(Config.GET_OTC_TRADE_INFO + "?rnd=" + String.valueOf(num)).params("trade_id", mData).execute(new StringCallback() {
            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            public void onSuccess(Response<String> response) {


                Log.i("1289182", response.body());

                if (mMicroAVLIDialog != null) {
                    mMicroAVLIDialog.dismiss();
                }
                if (mOtcActivityTvDerdettailSwip != null) {
                    mOtcActivityTvDerdettailSwip.setRefreshing(false);
                }

                String result = response.body().toString();

                try {

                    JSONObject jsonObject = new JSONObject(result);
                    if (jsonObject.getString(Config.KEY_CODE).equals("1")) {
                        initView(result);
                    } else {
                        Toast.makeText(cxt, jsonObject.getString("info"), Toast.LENGTH_SHORT).show();
                    }


                } catch (JSONException e) {
                    e.printStackTrace();

                }
            }
        });


    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    private void initView(String result) {

        Gson gson = new Gson();
        mOtcOrderDetailInfo = gson.fromJson(result, OTCOrderDetailInfo.class);
        String type = mOtcOrderDetailInfo.getData().getPay_type();
        String type_name = mOtcOrderDetailInfo.getData().getType();
        String danwei = mOtcOrderDetailInfo.getData().getDanwei();
//        if ("TYD".equals(type)) {
//            mOtcActivityTvDerdettailZhanghahoType.setText("天涯账号:");
//            mOtcActivityTvDerdettailMoney.setText(mOtcOrderDetailInfo.getData().getTotal() + "\t" + "TYZ");
//            mOtcActivityTvDerdettailPrice.setText(mOtcOrderDetailInfo.getData().getPrice() + "\t" + "TYZ");
//        } else {
//            String pay_type = mOtcOrderDetailInfo.getData().getPay_type();
//            if ("weixin".equals(pay_type)) {
//                Log.i("ldkwqmdqlwdi", "1");
//                mOtcActivityTvDerdettailZhanghahoType.setText("微信账号:");
//            }
//            if ("alipay".equals(pay_type)) {
//                Log.i("ldkwqmdqlwdi", "2");
//                mOtcActivityTvDerdettailZhanghahoType.setText("支付宝账号:");
//            }
//            mOtcActivityTvDerdettailMoney.setText(mOtcOrderDetailInfo.getData().getTotal() + "\t" + "CNY");
//            mOtcActivityTvDerdettailPrice.setText(mOtcOrderDetailInfo.getData().getPrice() + "\t" + "CNY");
//        }

        mImg = mOtcOrderDetailInfo.getData().getPay_info().getImg();

        if ("TYD".equals(type)) {
            mOtcActivityTvDerdettailZhanghahoType.setText("天涯账号:");
            otc_activity_tv_derdettail_zhanghaho_type_name.setVisibility(View.GONE);
            otc_activity_tv_derdettail_zhanghaho_name.setVisibility(View.GONE);

        } else if ("weixin".equals(type)) {
            Log.i("ldkwqmdqlwdi", "1");
            mOtcActivityTvDerdettailImag.setVisibility(View.VISIBLE);
            mOtcActivityTvDerdettailZhanghahoType.setText("微信账号:");
            Glide.with(this).load(Config.GETIMG + mImg).into(mOtcActivityTvDerdettailImag);
            otc_activity_tv_derdettail_zhanghaho_type_name.setVisibility(View.GONE);
            otc_activity_tv_derdettail_zhanghaho_name.setVisibility(View.GONE);

        } else if ("alipay".equals(type)) {
            Log.i("ldkwqmdqlwdi", "2");
            mOtcActivityTvDerdettailZhanghahoType.setText("支付宝账号:");
            mOtcActivityTvDerdettailImag.setVisibility(View.VISIBLE);
            Glide.with(this).load(Config.GETIMG + mImg).into(mOtcActivityTvDerdettailImag);
            otc_activity_tv_derdettail_zhanghaho_type_name.setVisibility(View.GONE);
            otc_activity_tv_derdettail_zhanghaho_name.setVisibility(View.GONE);
        } else {
            Log.i("ldkwqmdqlwdi", "3");
            otc_activity_tv_derdettail_zhanghaho_type_name.setVisibility(View.VISIBLE);
            mOtcActivityTvDerdettailZhanghahoType.setText("银行卡账户:");
            mOtcActivityTvDerdettailImag.setVisibility(View.INVISIBLE);
            otc_activity_tv_derdettail_zhanghaho_name.setVisibility(View.VISIBLE);
            String bank = mOtcOrderDetailInfo.getData().getPay_info().getBank();
            otc_activity_tv_derdettail_zhanghaho_name.setText(bank);

        }

        mOtcActivityTvDerdettailMoney.setText(mOtcOrderDetailInfo.getData().getTotal() + "\t" + danwei);
        mOtcActivityTvDerdettailPrice.setText(mOtcOrderDetailInfo.getData().getPrice() + "\t" + danwei);


        mOtcActivityTvDerdettailTime.setText("时间:" + "\t" + "\t" + mOtcOrderDetailInfo.getData().getCtime());
        mOtcActivityTvDerdettailDanhao.setText("订单号:" + "\t" + "\t" + mOtcOrderDetailInfo.getData().getTrade_id());
        mOtcActivityTvDerdettailNumber.setText(mOtcOrderDetailInfo.getData().getNum() + "\t" + type_name);

        mOtcActivityTvDerdettailOrder.setText(mOtcOrderDetailInfo.getData().getTrade_id());

        mOtcActivityTvDerdettailZhanghaho.setText(mOtcOrderDetailInfo.getData().getPay_info().getCard_no());

        mOther_contact = mOtcOrderDetailInfo.getData().getOther_contact();

        mTrade_status = mOtcOrderDetailInfo.getData().getTrade_type();

        if (mTrade_status.equals("sell")) {


            mOtcActivityTvDerdettailMaima.setText("我的信息");
            mOtcActivityTvDerdettailYi.setText("我已收款");
            mOtcActivityTvDerdettailShoukuan.setText(mOtcOrderDetailInfo.getData().getPay_info().getUser_name());
            mOtcActivityLinDerdettailOppositeName.setVisibility(View.VISIBLE);
            mOtcActivityTvDerdettailOppositeName.setText(mOtcOrderDetailInfo.getData().getOther_name());
            mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);

            setTeade("1");

        } else {

            Log.i("shfweufweufwu", "2");

            mOtcActivityTvDerdettailOppositeName.setText(mOtcOrderDetailInfo.getData().getOther_name());

            mOtcActivityTvDerdettailYi.setText("我已付款");
            mOtcActivityLinDerdettailOppositeName.setVisibility(View.VISIBLE);
            mOtcActivityTvDerdettailMaima.setText("卖家信息");
            mOtcActivityTvDerdettailShoukuan.setText(mOtcOrderDetailInfo.getData().getPay_info().getUser_name());
            mOtcActivityTvDerdettailDiss.setVisibility(View.VISIBLE);

            setTeade("2");

        }


        String ctime = mOtcOrderDetailInfo.getData().getCtime();

        Long aLong = string2Millis(ctime, "yyyy-MM-dd HH:mm:ss");
        long end = aLong + 15 * 60 * 1000;

        long timeStamp = System.currentTimeMillis();

        if (end < timeStamp) {
            mOtcActivityTvDerdettailCountdown.start(0);

        } else {
            mOtcActivityTvDerdettailCountdown.start(end - timeStamp);
        }


        mOtcActivityTvDerdettailCountdown.setOnCountdownEndListener(new CountdownView.OnCountdownEndListener() {
            @Override
            public void onEnd(CountdownView cv) {
                if (isShow) {
                    initDatas();
                }

            }
        });


    }

    private void setTeade(String ty) {


        if (ty.equals("1")) {

            String trade_status = mOtcOrderDetailInfo.getData().getTrade_status();

            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("2")) {
                mOtcActivityTvDerdettailYi.setClickable(false);
                mOtcActivityTvDerdettailYi.setText("--已成交--");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
                mOtcActivityTvDerdettailPayType.setText("");
            }

            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("-1")) {
                mOtcActivityTvDerdettailYi.setClickable(false);
                mOtcActivityTvDerdettailYi.setText("--已取消--");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
                mOtcActivityTvDerdettailPayType.setText("");
            }


            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("1")) {
                mOtcActivityTvDerdettailYi.setClickable(true);
                mOtcActivityTvDerdettailYi.setText("我已收款");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#FFFFFF"));
                mOtcActivityTvDerdettailYi.setBackground(getResources().getDrawable(R.drawable.shape_otc_real_name_set));

                if (mOtcOrderDetailInfo.getData().getTrade_type().equals("sell")) {
                    mOtcActivityTvDerdettailPayType.setText("对方已支付");
                } else {
                    mOtcActivityTvDerdettailPayType.setText("已支付");
                }

            }


            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("0")) {


                if (mOtcOrderDetailInfo.getData().getTrade_type().equals("sell")) {
                    mOtcActivityTvDerdettailPayType.setText("对方待支付");


                } else {
                    mOtcActivityTvDerdettailPayType.setText("待支付");
                }

//
//            mOtcActivityTvDerdettailYi.setClickable(false);
//            mOtcActivityTvDerdettailYi.setText("--未付款--");
//            mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
//            mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
            }

            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("-2")) {
//                mOtcActivityTvDerdettailYi.setClickable(false);
//                mOtcActivityTvDerdettailYi.setText("--已锁定--");
//                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
//                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);

                mOtcActivityTvDerdettailYi.setClickable(true);
                mOtcActivityTvDerdettailYi.setText("我已收款");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#FFFFFF"));
                mOtcActivityTvDerdettailYi.setBackground(getResources().getDrawable(R.drawable.shape_otc_real_name_set));
                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
                mOtcActivityTvDerdettailPayType.setText("");
            }

        } else {
            String trade_status = mOtcOrderDetailInfo.getData().getTrade_status();
            Log.i("qlwidjqoiwdjoqiw", trade_status);

            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("2")) {
                mOtcActivityTvDerdettailYi.setClickable(false);
                mOtcActivityTvDerdettailYi.setText("--已成交--");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
                mOtcActivityTvDerdettailPayType.setText("");
            }

            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("-1")) {
                mOtcActivityTvDerdettailYi.setClickable(false);
                mOtcActivityTvDerdettailYi.setText("--已取消--");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
                mOtcActivityTvDerdettailPayType.setText("");
            }


            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("1")) {
                mOtcActivityTvDerdettailYi.setClickable(false);
                mOtcActivityTvDerdettailYi.setText("--已付款--");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);

                if (mOtcOrderDetailInfo.getData().getTrade_type().equals("sell")) {
                    mOtcActivityTvDerdettailPayType.setText("对方已支付");
                } else {
                    mOtcActivityTvDerdettailPayType.setText("已支付");
                }

            }


            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("0")) {


                if (mOtcOrderDetailInfo.getData().getTrade_type().equals("sell")) {
                    mOtcActivityTvDerdettailPayType.setText("对方待支付");


                } else {
                    mOtcActivityTvDerdettailPayType.setText("待支付");
                }

//
//            mOtcActivityTvDerdettailYi.setClickable(false);
//            mOtcActivityTvDerdettailYi.setText("--未付款--");
//            mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
//            mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
            }

            if (mOtcOrderDetailInfo.getData().getTrade_status().equals("-2")) {


                mOtcActivityTvDerdettailPayType.setText("待支付");

                mOtcActivityTvDerdettailYi.setClickable(true);
                mOtcActivityTvDerdettailYi.setText("我已付款");
                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#FFFFFF"));
                mOtcActivityTvDerdettailYi.setBackground(getResources().getDrawable(R.drawable.shape_otc_real_name_set));
                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
                mOtcActivityTvDerdettailPayType.setText("");
//                mOtcActivityTvDerdettailYi.setText("--已锁定--");
//                mOtcActivityTvDerdettailYi.setTextColor(Color.parseColor("#272736"));
//                mOtcActivityTvDerdettailYi.setBackgroundResource(R.color.white);
//                mOtcActivityTvDerdettailDiss.setVisibility(View.GONE);
//                mOtcActivityTvDerdettailPayType.setText("");
            }
        }


    }

    @Override
    public void setData() {

    }

    @Override
    public void onClick(View v) {

    }


    @OnClick({R.id.otc_activity_tv_derdettail_imag, R.id.otc_activity_tv_derdettail_diss, R.id.otc_activity_tv_derdettail_yi, R.id.iv_back, R.id.otc_activity_tv_derdettail_shenshu, R.id.otc_activity_tv_derdettail_call})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.otc_activity_tv_derdettail_imag:

                new OTCBigImagDialog(this, mImg).show();

                break;
            case R.id.otc_activity_tv_derdettail_diss:

                new OTCCancelConfirmDialog(this, mData, mOtcOrderDetailInfo).show();
                break;
            case R.id.otc_activity_tv_derdettail_yi:

                String url = "";
                if (!TextUtils.isEmpty(mTrade_status)) {

                    if (mTrade_status.equals("sell")) {
                        url = Config.OTC_GET;
                    } else {
                        url = Config.OTC_PAY;
                    }
                } else {

                    return;
                }


                new OTCConfirmDialog(this, url, mData, mOtcOrderDetailInfo).show();

                break;

            case R.id.iv_back:
                finish();
                break;

            case R.id.otc_activity_tv_derdettail_shenshu:

                startActivity(new Intent(this, OTCStateActivity.class).putExtra("data", mData));

                break;

            case R.id.otc_activity_tv_derdettail_call:

                if (!TextUtils.isEmpty(mOther_contact)) {
                    callPhone(mOther_contact);

                } else {

                    Util.showSnachBar(OTCOrderdetailActivity.this, getResources().getColor(R.color.red), "暂无数据");
                }


                break;
        }
    }

    /**
     * 拨打电话（跳转到拨号界面，用户手动点击拨打）
     *
     * @param phoneNum 电话号码
     */
    public void callPhone(String phoneNum) {

        Intent intent = new Intent(Intent.ACTION_DIAL);
        Uri data = Uri.parse("tel:" + phoneNum);
        intent.setData(data);
        startActivity(intent);

    }

//    private void SnackbarShow(String ms) {
//
//        Snackbar snackbar = ShortSnackbar(mOtcActivityTvDerdettailMoney, ms, Color.parseColor("#ffffff"), Color.parseColor("#272736"));
//        snackbar.show();
//    }
//
//    public static Snackbar ShortSnackbar(View view, String message, int messageColor, int backgroundColor) {
//        Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
//        setSnackbarColor(snackbar, messageColor, backgroundColor);
//        return snackbar;
//    }
//
//    /**
//     * 设置Snackbar文字和背景颜色
//     *
//     * @param snackbar
//     * @param messageColor
//     * @param backgroundColor
//     */
//    public static void setSnackbarColor(Snackbar snackbar, int messageColor, int backgroundColor) {
//        View view = snackbar.getView();
//
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
//            TextView message = (TextView) snackbar.getView().findViewById(R.id.snackbar_text);
//            //View.setTextAlignment需要SDK>=17
//            message.setTextAlignment(View.TEXT_ALIGNMENT_GRAVITY);
//            message.setGravity(Gravity.CENTER);
//        }
//
//        if (view != null) {
//            view.setBackgroundColor(backgroundColor);
//            ((TextView) view.findViewById(R.id.snackbar_text)).setTextColor(messageColor);
//        }
//    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(String event) {
        if (event.equals("OTCSELL")) {
            initDatas();
        }
        if (event.equals("OTCCALL")) {
            initDatas();
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }


    /**
     * 日期字符串转时间戳
     */
    @RequiresApi(api = Build.VERSION_CODES.N)
    public static Long string2Millis(String dateStr, String formatStr) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
            long time = simpleDateFormat.parse(dateStr).getTime();

            return time;
        } catch (Exception e) {
            return 0L;
        }
    }


    @Override
    protected void onResume() {
        super.onResume();
        initDatas();
        isShow = true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        isShow = false;

    }
}
